init python:
    def tackle_distance(drags, drop):
        """实现检查碎片是否到达指定位置,当到达指定位置自动固定到该位置并切换到下一幕"""
        if not drags:
            return
        
        drag = drags[0]
        current_drag_name = drag.drag_name
        if not drop:
            renpy.notify("不在这里吗")
            return
        # 检查是否放到了正确的目标上
        if drop.drag_name != store.correct_list[current_drag_name]:
            renpy.notify("好像不是这个")
            return
        
        drag_center_x = drag.x + drag.w/2
        drag_center_y = drag.y + drag.h/2
        drop_center_x = drop.x + drop.w/2
        drop_center_y = drop.y + drop.h/2

        x = int(drop_center_x - drag.w/2)
        y = int(drop_center_y - drag.h/2)

        distance = ((drag_center_x - drop_center_x)**2 + (drag_center_y - drop_center_y)**2)**0.5
        # 放置成功
        if distance <= 30:
            drag.draggable = False
            drag.snap(x, y, 1)
            renpy.notify("照片有了反应...")
            #设置当前拼图为完成状态
            store.puzzle_completed[current_drag_name] = True
            renpy.restart_interaction()
            renpy.jump(store.correct_dialogue[current_drag_name])
            return
            
        elif 30 < distance <= 100:
            renpy.notify("应该就是这个了")            
        else:
            renpy.notify("应该在附近吗")



screen drag_pages:
    draggroup:
        # 目标区域
        drag:
            drag_name "target_1"
            child Fixed(
                Solid("#ff0000", xsize=60, ysize=2),  # 上边框
                Solid("#ff0000", xsize=60, ysize=2, ypos=58),  # 下边框
                Solid("#ff0000", xsize=2, ysize=60),  # 左边框
                Solid("#ff0000", xsize=2, ysize=60, xpos=58),  # 右边框
                xsize=60,
                ysize=60
            )
            xpos 400 ypos 600
            draggable False
            droppable True
            
        drag:
            drag_name "target_2"
            child Fixed(
                Solid("#ff0000", xsize=60, ysize=2),  # 上边框
                Solid("#ff0000", xsize=60, ysize=2, ypos=58),  # 下边框
                Solid("#ff0000", xsize=2, ysize=60),  # 左边框
                Solid("#ff0000", xsize=2, ysize=60, xpos=58),  # 右边框
                xsize=60,
                ysize=60
            )
            xpos 700 ypos 300
            draggable False
            droppable True
            
        drag:
            drag_name "target_3"
            child Fixed(
                Solid("#ff0000", xsize=60, ysize=2),  # 上边框
                Solid("#ff0000", xsize=60, ysize=2, ypos=58),  # 下边框
                Solid("#ff0000", xsize=2, ysize=60),  # 左边框
                Solid("#ff0000", xsize=2, ysize=60, xpos=58),  # 右边框
                xsize=60,
                ysize=60
            )
            xpos 400 ypos 300
            draggable False
            droppable True
        drag:
            drag_name "target_4"
            child Fixed(
                Solid("#ff0000", xsize=60, ysize=2),  # 上边框
                Solid("#ff0000", xsize=60, ysize=2, ypos=58),  # 下边框
                Solid("#ff0000", xsize=2, ysize=60),  # 左边框
                Solid("#ff0000", xsize=2, ysize=60, xpos=58),  # 右边框
                xsize=60,
                ysize=60
            )
            xpos 700 ypos 600
            draggable False
            droppable True
        
        # 可拖拽的拼图
        drag:
            drag_name "drag_1"
            child Solid("#8cff27", xsize=50, ysize=50)
            xpos 200 ypos 100
            draggable True
            drag_raise True  
            dragged tackle_distance
        
        # 当第一个拼图完成时显示第二个拼图
        if puzzle_completed["drag_1"]:
            drag:
                drag_name "drag_2"
                child Solid("#e9ff27", xsize=50, ysize=50)
                xpos 200 ypos 100
                draggable True
                drag_raise True
                dragged tackle_distance

        # 当第二个拼图完成时显示第三个拼图
        if puzzle_completed["drag_2"]:
            drag:
                drag_name "drag_3"
                child Solid("#13c3db", xsize=50, ysize=50)
                xpos 200 ypos 100
                draggable True
                drag_raise True
                dragged tackle_distance
        # 第四个拼图
        if puzzle_completed["drag_3"]:
            drag:
                drag_name "drag_4"
                child Solid("#c640e8", xsize=50, ysize=50)
                xpos 200 ypos 100
                draggable True
                drag_raise True
                dragged tackle_distance
# 定义控制变量
default puzzle_completed = {"drag_1": False, "drag_2": False, "drag_3": False,"drag_4": False}
default correct_dialogue = {"drag_1": "next_1", "drag_2": "next_2", "drag_3": "next_3","drag_4":"next_4"}
default correct_list = {"drag_1": "target_1", "drag_2": "target_2", "drag_3": "target_3","drag_4":"target_4"}

image Scene1 = 'images/1.png'
"""
label start: 
    # 重置所有状态
    $ puzzle_completed = {"drag_1": False, "drag_2": False, "drag_3": False,"drag_4":False}
    show screen drag_pages
    "放置这块拼图吧"
    
    # 等待所有拼图完成
    # 使用列表来管理拼图信息
    
    # 等待每个拼图完成
    
    while not puzzle_completed['drag_1']:
        pause(0.5)

    jump next
"""
label next_1:
    "第一块拼图放到了该放的地方"
    "可以放第二块了"
    while not puzzle_completed['drag_2']:
        "可以放第二块了"
        pause(0.5)
    
label next_2:
    "第二块拼图放到了该放的地方"
    "可以放第三块了"
    while not puzzle_completed['drag_3']:
        "可以放第三块了"
        pause(0.5)
label next_3:
    "第三块也放了进去"
    "最后一块了"
    while not puzzle_completed['drag_4']:
        "最后一个位置了"
        pause(0.5)
label next_4:
    "所有的拼图都放在了应在的地方"
    jump next
label next:
    hide screen drag_pages with Dissolve(2) 
    show Scene1 with Dissolve(2)
    "相框恢复了原来的模样，显现出往日的影像"